var arr1 = (costrecord.showscore).split('.html');
var arr2 = (costrecord.showscoreyx).split('.html');
var pjpath='';

var costrecordpage = 0;

$(function(){
    $('#recordlist').html('');
    loadRecordlist('init');
});

/*加载消费记录列表*/
function loadRecordlist(parm){
    $.Dialog.loading();
    $.ajax({
        url: costrecord.loadcostRecord + "&page="+costrecordpage,
        type:"get",
        dataType:"json",
        success:function(data){
            if(data){
                if(parm == 'init'){
                    $.Dialog.close();
                }
                else{
                    $.Dialog.success('加载成功');
                }
                $.each(data, function(index, row){
                    row.date = (row.date).split(' ')[0];
                    var item = $('<a class="p_10 arrow_icon mr_10">\n    <div class="recorditem_c">\n        <h1></h1>\n        <h2><b></b><span></span></h2>\n        <i>服务已评价</i>\n        <strong>药效已评价</strong>\n    </div>\n</a>')
                    var line = $('<div class="single_item_line"></div>');
                    item.attr('data-id', row.listid);
                    item.attr('data-mdcode', row.mdcode);
                    item.attr('data-dbid', row.dbid);
                    item.find('h1').text(row.com_zip_name);
                    item.find('h2 > span').text(row.date);
                    switch (row.jf_type){
                        case "1":
                            row.type = '消费 +';
                            break;
                        case "2":
                            row.type = '退货 -';
                            break;
                        case "3":
                            row.type = '赠送 +';
                            break;
                        case "4":
                            row.type = '兑换 -';
                            break;
                        case "5":
                            row.type = '转移 +';
                            break;
                    }
                    item.find('h2 > b').text(row.type + row.jf_num + '分');
                    if(!row.statu_fw){
                        item.find('i').addClass('red');
                        item.find('i').text('服务未评价');
                    }
                    if(!row.statu_yx){
                        item.find('strong').addClass('red');
                        item.find('strong').text('药效未评价');
                    }
                    $('#recordlist').append(item);
                    $('#recordlist').append(line);
                })
            }
            else{
                $.Dialog.fail('没有记录了！');
            }

        }
    });
}

/*加载更多*/
$('#more_btn').click(function(){
    costrecordpage++;
    loadRecordlist();
})

/*查看评价*/
$('.recordlist').delegate('a','click',function(){
    $('.morecard').show();
    pjpath = '/listid/' + $(this).attr('data-id') + '/mdcode/' + $(this).attr('data-mdcode') + '/dbid/' + $(this).attr('data-dbid') + '.html';
//    location.href = pjpath;
});

/*服务评价*/
$('#fw_btn').click(function(){
    if(pjpath){
        location.href = arr1[0] + pjpath;
    }
});

/*服务评价*/
$('#yx_btn').click(function(){
    if(pjpath){
        location.href = arr2[0] + pjpath;
    }
});


/*服务评价*/
$('#cancel_btn').click(function(){
    $('.morecard').hide();
    pjpath='';
});